//
//  GCFindViewController.m
//  GoldChampion
//
//  Created by Mac on 2018/4/12.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "GCChaZhaoViewController.h"
#import "GCChaoZhaoFunTableViewCell.h"
#import "GCChaZhaoTagTableViewCell.h"
#import "GCTopicDetailViewController.h"
@interface GCChaZhaoViewController ()
@property(nonatomic, strong) STSegementButton                     *segementButton;
@end

@implementation GCChaZhaoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"查找";
    [self configSubView];
    // Do any additional setup after loading the view.
}
- (void)configSubView{
    __weak typeof(self) weakSelf =  self;
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 30)];
    header.backgroundColor = [UIColor whiteColor];
    
    STButton * searchButton = [[STButton alloc] initWithFrame:CGRectMake(20, 15, UIScreenWidth - 40, 35)
                                                        title:@"查找标签"
                                                   titleColor:SecendTextColor
                                                    titleFont:16
                                                 cornerRadius:4
                                              backgroundColor:self.tableView.backgroundColor
                                              backgroundImage:nil
                                                        image:[UIImage imageNamed:@"搜索8"]];
    searchButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    searchButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    [searchButton setClicAction:^(UIButton *sender) {
        
    }];
    [header addSubview:searchButton];
    
    UIView * line = [[UIView alloc] initWithFrame:CGRectMake(0, searchButton.bottom + 20, UIScreenWidth, 10)];
    line.backgroundColor = self.tableView.backgroundColor;
    [header addSubview:line];
    
    
    
    self.segementButton = [[STSegementButton alloc] initWithFrame:CGRectMake(0, line.bottom, UIScreenWidth, 44)
                                                         andTitle:@[@"用户",@"标签"] handle:^(STSegementButton *sender) {
                                                             
                                                              [weakSelf.tableView reloadData];
                                                         }];
    self.segementButton.backgroundColor = [UIColor whiteColor];
    self.segementButton.lineSelectedColor = TM_redColor;
    self.segementButton.butTitleSelectedColor = TM_redColor;
    self.segementButton.butTitleColor = TM_secendTextColor;
    self.segementButton.lineColor = [UIColor whiteColor];
    self.segementButton.cureentIndex = 0;
    self.segementButton.autoMoveWithClic = YES;
    [header addSubview:self.segementButton];
    
    header.height = self.segementButton.bottom;
    self.tableView.tableHeaderView = header;
    
    [self.tableView registerClass:[GCChaoZhaoFunTableViewCell class] forCellReuseIdentifier:@"funCell"];
    [self.tableView registerClass:[GCChaZhaoTagTableViewCell class] forCellReuseIdentifier:@"tagCell"];
    
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1    ;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 30;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.segementButton.cureentIndex == 0) {
        return [GCChaoZhaoFunTableViewCell cellHeight];
    }
    return [GCChaZhaoTagTableViewCell cellHeight];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (self.segementButton.cureentIndex == 0) {
      return 44;
    }
    return 0.01;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (self.segementButton.cureentIndex == 0) {
        UIView * sectionHeder = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 44)];
        STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(self.insetX, 0, UIScreenWidth, 44)
                                                         text:@"可能感兴趣的人"
                                                    textColor:SecendTextColor
                                                         font:16
                                                  isSizetoFit:NO
                                                textAlignment:NSTextAlignmentLeft];
        [sectionHeder addSubview:titleLable];
        return sectionHeder;
    }
    return [UIView new];
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (self.segementButton.cureentIndex == 0) {
        GCChaoZhaoFunTableViewCell * cell = [self.tableView dequeueReusableCellWithIdentifier:@"funCell"];
        [cell debugRandromImage];
        return cell;
    }
    GCChaZhaoTagTableViewCell * cell = [self.tableView dequeueReusableCellWithIdentifier:@"tagCell"];
    [cell debugRandromImage];
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (self.segementButton.cureentIndex == 1) {
        [self.navigationController pushViewController:[GCTopicDetailViewController new] animated:YES];
    }
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}

@end
